<%# locals: () -%>
<%= render @above if @above %>

<% already_printed_newest_line = false %>
<ol class="stories list <%= action_name == "hidden" ? "show_hidden" : "" %>">
  <% @stories.each do |story| %>
    <% if action_name == "newest" &&
      !already_printed_newest_line &&
      @last_read_timestamp &&
      @last_read_timestamp.after?(story.created_at) %>
      <div class="last_read_newest">Last Read</div>
      <% already_printed_newest_line = true %>
    <% end %>
<%#heinous_inline_partial(stories/_listdetail.html.erb)%>
<%# Do not edit, the content before /heinous_inline_partial comes from the named partial %>
<%# locals: (story:) -%>

<%# remember: _singledetail replicates a lot of this for the single-story view %>

<%#
  The h-entry, u-report-of, u-url and h-card css classes are necessary
  for the webmentions support. http://microformats.org/wiki/h-entry

  This has apparently useless <span> tags explained in a comment in CSS
  around .negative_1 in CSS (introduced same commit as this comment).
%>
<li id="story_<%= story.short_id %>" data-shortid="<%= story.short_id %>"
class="story <%= story.current_upvoted? ? "upvoted" : "" %>
<%= story.current_flagged? ? "flagged" : "" %>
<%= story.negativity_class %>
<%= story.is_hidden_by_cur_user ? "hidden" : "" %>
<%= story.is_saved_by_cur_user ? "saved" : "" %>
<%= story.is_deleted? ? "deleted" : "" %>">
<div class="story_liner h-entry">
  <div class="voters">
    <%= link_to (story.show_score_to_user?(@user) ? story.score : '~'),
                (@user ? '': login_path), :class => "upvoter" %>
  </div>
  <div class="details">
    <span role="heading" aria-level="1" class="link h-cite u-repost-of">
      <% if story.can_be_seen_by_user?(@user) %>
        <a class="u-url" href="<%= Routes.url_or_comments_path(story) %>" rel="ugc <%= story.send_referrer? ? '' : 'noreferrer' %>"><%= story.title %></a>
      <% end %>
      <% if story.is_gone? %>
        [Story removed by <%= story.is_moderated? ? "moderator" : "submitter" %>]
      <% end %>
    </span>
    <% if story.stories_count > 0 %>
      <span class="merge"></span><%= story.stories_count + 1 %>
    <% elsif story.merged_story_id %>
      <span class="merge"></span>merged
    <% end %>
    <% if story.markeddown_description.present? %>
      <a class="description_present" title="<%= truncate(story.description,
        :length => 500) %>" href="<%= Routes.title_path story %>">&#x2636;</a>
    <% end %>
    <% if story.can_be_seen_by_user?(@user) %>
      <span class="tags">
        <% story.tags.each do |tag| %>
          <%= tag_link(tag) %>
        <% end %>
      </span>
      <% if story.origin.present? %>
        <%= link_to story.origin.identifier, origin_path(story.origin), class: 'domain' %>
      <% elsif story.domain.present? %>
        <%= link_to story.domain.domain, domain_path(story.domain), class: 'domain' %>
      <% end %>
    <% end %>

    <% if @user&.show_story_previews? %>
      <% if (sc = story.description_or_story_text(500)).present? %>
        <div class="story_content">
          <%= sc %>
        </div>
      <% end %>
    <% end %>

    <div class="byline">
      <%= inline_avatar_for @user, story.user %>
      <% if story.previewing %>
        <% if story.user_is_author? %>
          <span> authored by </span>
        <% else %>
          <span> via </span>
        <% end %>

        <%= styled_user_link story.user, story, class: ['u-author', 'h-card'] %>
        <span> just now </span>
      <% else %>
        <% if story.user_is_author? %>
          <span> authored by </span>
        <% else %>
          <span> via </span>
        <% end %>
        <%= styled_user_link story.user, story, class: ['u-author', 'h-card'] %>

        <%= how_long_ago_label(story.created_at) %>

        <% if story.is_editable_by_user?(@user) %>
          <span> | </span>
          <a href="<%= edit_story_path(story.short_id) %>" class="<%= story.has_suggestions? ? "story_has_suggestions" : "" %>">edit</a>
        <% end %>
        <% if @user&.is_moderator? %>
          <span> | </span>
          <a href="<%= edit_mod_story_path(story.short_id) %>" class="<%= story.has_suggestions? ? "story_has_suggestions" : "" %>">mod edit</a>
        <% end %>
        <% if story.can_have_suggestions_from_user?(@user) %>
          <span> | </span><%= link_to "suggest", new_story_suggestion_path(story.short_id),
            :class => "suggester" %>
        <% end %>
        <% if !story.is_gone? && @user %>
          <% if @user && story.current_flagged? %>
            <span> | </span><a class="flagger">unflag (<%=
              Vote::STORY_REASONS[story.current_vote[:reason]].to_s.downcase %>)</a>
          <% elsif @user && @user.can_flag?(story) %>
            <span> | </span>
            <span class="dropdown_parent">
              <a class="flagger">flag</a>
            </span>
          <% end %>
          <% if story.is_hidden_by_cur_user %>
            <span> | </span><%= link_to "unhide", story_unhide_path(story.short_id), :class => "hider" %>
          <% else %>
            <span> | </span><%= link_to "hide", story_hide_path(story.short_id), :class => "hider" %>
          <% end %>
          <% if !story.is_saved_by_cur_user %>
            <span> | </span><%= link_to "save", story_save_path(story.short_id), :class => "saver" %>
          <% end %>
        <% end %>
        <% if story.is_saved_by_cur_user %>
          <span> | </span><%= link_to "unsave", story_unsave_path(story.short_id), :class => "saver" %>
        <% end %>
        <% if story.url.present? && (!story.is_gone? || @user.try(:is_moderator?))  %>
          <span> | </span>
          <span class="dropdown_parent">
            <input id="archive_<%= story.short_id %>" class="archive_button" type="checkbox">
            <label for="archive_<%= story.short_id %>" tabindex="0">caches</label>
            <div class="archive-dropdown">
              <a href="<%= story.archiveorg_url %>">Archive.org</a>
              <a href="<%= story.archivetoday_url %>">Archive.today</a>
              <a href="<%= story.ghost_url %>">Ghostarchive</a>
            </div>
          </span>
        <% end %>
        <% if !story.is_gone? || @user.try(:is_moderator?) %>
          <span class="comments_label">
            <span> | </span>
            <a role="heading" aria-level="2" href="<%= Routes.title_path story %>">
            <% if story.comments_count == 0 %>
              no comments</a>
            <% else %>
              <%= story.comments_count %> <%= 'comment'.pluralize(story.comments_count) %></a>
            <% end %>
          </span>
        <% end %>
      <% end %>
    </div>
  </div>
</div>
<a href="<%= Routes.title_path story %>" class="mobile_comments <%= story.comments_count == 0 ? "zero" : "" %>" style="display: none;">
  <span><%= story.comments_count %></span>
</a>
</li>

<%#/heinous_inline_partial(stories/_listdetail.html.erb)%>
  <% end %>
</ol>

<%= render @below if @below %>

<div class="morelink">
  <% if @page && @page > 1 %>
    <%= link_to raw("&lt;&lt; Page #{@page - 1}"), @root_path ? "/page/#{@page - 1}" : { controller: controller_name, action: action_name, page: @page - 1 }.merge(@next_page_params || {}) %>
  <% end %>

  <% if @show_more %>
    <% if @page && @page > 1 %>
      |
    <% end %>
    <%= link_to raw("Page #{@page + 1} &gt;&gt;"), @root_path ? "/page/#{@page + 1}" : { controller: controller_name, action: action_name, page: @page + 1 }.merge(@next_page_params || {}) %>
  <% end %>
</div>
